<?php

namespace Biz\model\brandIndex;

use Doraemon\pockets\datebase\BaseDbModel;

class BrandBanner extends BaseDbModel
{

    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'hhz_store';

    const _TABLE_NAME = 'brand_banner';

    const STATUS_NORMAL = 1;
    const STATUS_DELETE = 9;
    const STATUS = [
        self::STATUS_NORMAL => '正常',
        self::STATUS_DELETE => '删除'
    ];


    public static function getBanners()
    {
        return self::select('*', [
            "banner_status" => self::STATUS_NORMAL,
            "ORDER" => [
                "banner_sort" => "ASC",
                "addtime" => "DESC"
            ]
        ]);
    }

    //添加
    public static function addData($data)
    {
        self::insert($data);
        return self::id();
    }

    //修改
    public static function editData($data, $where = [])
    {
        if(!$where) {
            return false;
        }
        return self::update($data, $where);
    }


    public static function getBannerById($id)
    {
        return self::get('*', [
            "id" => $id,
            "banner_status" => self::STATUS_NORMAL,
            "start_time[<]" => date('Y-m-d H:i:s', time()),
            "end_time[>]" => date('Y-m-d H:i:s', time())
        ]);
    }

    public static function getBannerByTime($id = 0, $start_time, $end_time)
    {
        return self::select('*', [
            "id[!]" => $id,
            "banner_status" => self::STATUS_NORMAL,
            "start_time[<]" => $end_time,
            "end_time[>]" => $start_time
        ]);
    }

    public static function getBannersOnline()
    {
        return self::select('*', [
            "banner_status" => self::STATUS_NORMAL,
            "start_time[<]" => date('Y-m-d H:i:s', time()),
            "end_time[>]" => date('Y-m-d H:i:s', time()),
            "ORDER" => [
                "banner_sort" => "ASC",
                "addtime" => "DESC"
            ]
        ]);
    }


}

